package com.worldcup.common;

/**
 * @author duwan.zq
 * @date 2018/05/22
 */
public class CommonResult<T> {

    public final static int SUCCESS_CODE = 0;

    public final static int FAILED_CODE =  -1;

    public final static String DEFUALT_SUCCESS_MSG = "success";

    private int code;

    private long timestamp;

    private T data;

    private String msg;

    private CommonResult(int code, T data, String msg){
        this.code = code;
        this.timestamp = System.currentTimeMillis() / 1000;
        this.data = data;
        this.msg = msg;
    }

    public static <T> CommonResult<T> buildSuccess(){
        return new CommonResult<>(SUCCESS_CODE, null, DEFUALT_SUCCESS_MSG);
    }

    public static <T> CommonResult<T> buildSuccess(T data){
        return new CommonResult<>(SUCCESS_CODE, data, DEFUALT_SUCCESS_MSG);
    }

    public static <T> CommonResult<T> buildFailed(String msg){
        return new CommonResult<>(FAILED_CODE, null, msg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
